home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18435 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  52 lines

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: easy c++ question
  5. Date: Sat, 20 Apr 1996 04:37:46 GMT
  6. Organization: Netcom
  7. Message-ID: <3178695f.194916034@nntp.ix.netcom.com>
  8. References: <316901DA.3138C677@ablecom.net> <66W25t5UoNB@jth.ping.de> <Pine.OSF.3.91.960411092945.20958C-100000@bud.cc.swin.edu.au> <3172B4A9.6DFF@aai.arco.com> <31783CA2.3FD5@compuserv.com>
  9. NNTP-Posting-Host: ix-dc16-01.ix.netcom.com
  10. X-NETCOM-Date: Fri Apr 19 11:38:43 PM CDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. "David Visage (Alias Sid)" <"102276,2374"@compuserv.com> wrote:
  14.  
  15. > > > if you have a class myclass with a constructor and you do
  16. > > >
  17. > > > myclass *a;
  18. > > > a=new myclass[5];
  19. > > >
  20. > > > the constructor is not called for every member (a[0], a[1]..)
  21. > > > Does this help?
  22. > > >  Newbs
  23. > > 
  24. > > John,
  25. > > 
  26. > > I am afraid you made a mistake here. The default constructor
  27. > > is called for each array element. If there is no default
  28. > > constructor, the array allocation is not allowed.
  29. > If you do not declare a default constuctor, then the array allocation is allowed.
  30. > From what I understand, if you do not supply a default constructor, then most
  31. > compilers will generate one for you.  Of course, I could be wrong, but who said
  32. > I knew everything?
  33.  
  34. ALL properly working compilers will generate a default constructor
  35. ONLY IF there is no user-declared constructor.
  36.  
  37.     class A {
  38.       public:
  39.         A(int);
  40.     };
  41.  
  42.     class B {
  43.     };
  44.  
  45.     A a[10];    // illegal -- no default constructor
  46.     B b[10];    // legal -- generated default constructor used
  47.  
  48.  
  49. Michael M Rubenstein
  50.